[Rails] checkbox to update attribute

Posted by Jeff on Stack Overflow See other posts from Stack Overflow or by Jeff
Published on 2010-03-13T16:34:45Z Indexed on 2010/03/13 22:05 UTC
Read the original article Hit count: 234

Filed under:
|
|

[Updated a bit] I have a Task model that has a :completed boolean attribute. If I click on it I want it to execute the 'finish' method. The main problem is that I am displays a series of checkboxes in a list and subsequent checkboxes after the first one are ignored. The method is never called for the given task/checkbox combo.

I have this chunk of code in my view:

<% current_user.tasks.each do |t|%>
      <% if t.completed == false %>
          <%= check_box_tag :completed, true, checked = false   %>
          <%= observe_field :completed, :url => { :controller => 'tasks', :action => :finish , :id => t.id },
              :frequency => 0.25,
              :update => :completed,
              :with => true
          %>

and my finish method looks like this:

def finish
      @task = Task.find(params[:id])
      new = {:completed => true}
      @task.update_attributes(new)
      render :update do |page|
      page.replace_html "taskListing", :partial => 'home/task_listing'
 end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about AJAX